<?php
declare(strict_types=1);
/**
 * 会员中心
 * @author chenshubo
 */
namespace App\Controller\Shop;

use App\Model\PssModel\Accountlog;
use App\Model\PssModel\Business;
use App\Model\PssModel\GoodsCart;
use App\Service\Code\Normal;
use Hyperf\HttpServer\Contract\RequestInterface;
use Service\UserService\AccountEnterpriseService;
class MemberController extends AbstractController
{
    /**
     * 个人中心显示
     */
    public function index(RequestInterface $request)
    {
        $param = $request->getAttribute('param');
        $binfo = $param['binfo'];
        $arr = [
            'account'                           => $binfo['account'],
            'user_source'                       => $binfo['user_source'],
            'user_type_name'                    => Business::instance()->userType[$binfo['user_type']] ??'普通会员',
            'total_balance_settlement_money'    => number_format((float)$binfo['total_balance_settlement_money'],2),
            'totalCartGoods'                    => GoodsCart::instance()->where('bid',$binfo['bid'])->where('is_down',0)->count(),
            'enterprise_name'                   => $binfo['enterprise_name'],
            'enterprise_auth_type'              => $binfo['enterprise_auth_type'],
            'enterprise_auth_no'                => $binfo['enterprise_auth_no'],
            'enterprise_auth_time'              => !empty($binfo['enterprise_auth_time']) ? date("Y-m-d H:i:s",$binfo['enterprise_auth_time']) : '',
        ];
        return Normal::returnCode(Normal::SUC,"获取成功",$arr);
    }

    /**
     * 账户变更资金日志
     * @param RequestInterface $request
     */
    public function balanceChangeRecord(RequestInterface $request)
    {
        $binfo = $request->getAttribute('param')['binfo'];
        $body  = $request->getAttribute('param')['body'];
        return Accountlog::instance()->getAccoutLogList([
            'binfo'=>$binfo,
            'body' => $body
        ]);
    }

    /**
     * 账户变更资金日志导出
     * @param RequestInterface $request
     * @return unknown[]|string[]|array[]|mixed
     */
    public function balanceChangeRecordExport(RequestInterface $request)
    {
        $binfo = $request->getAttribute('param')['binfo'];
        $body  = $request->getAttribute('param')['body'];
        return Accountlog::instance()->accoutLogListExport([
            'binfo'=>$binfo,
            'body' => $body
        ]);
    }
    
    /**
     * 账户获取认证选项
     * @param RequestInterface $request
     * @return unknown[]|string[]|array[]|mixed
     */
    public function accountEnterpriseAuthTypeOption(RequestInterface $request)
    {
        return AccountEnterpriseService::instance()->accountEnterpriseAuthTypeOption();
    }
    
    /**
     * 账户企业资质认证
     * @param RequestInterface $request
     * @return unknown[]|string[]|array[]|mixed
     */
    public function accountEnterpriseCheckSave(RequestInterface $request)
    {
        $binfo = $request->getAttribute('param')['binfo'];
        $body  = $request->getAttribute('param')['body'];
        return AccountEnterpriseService::instance()->checkSaveUserPrise([
            'binfo'=>$binfo,
            'body' => $body
        ]);
    }
}